﻿using System;
using System.Collections.Generic;
using System.DrawingCore;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace StorageBox
{
    using DrawPoint = System.DrawingCore.Point;
    using MySize = StorageBox.Size;
    public class ApplyElement : FrameworkElement
    {
        private static int _maxID = 1;

        public ApplyData Data;
        /// <summary>
        /// 边长系数
        /// </summary>
        public MySize SideLength { get { return Data.Langth; } }
        /// <summary>
        /// 方位
        /// </summary>
        public DrawPoint Location { get; set; } = new DrawPoint(-1, -1);
        /// <summary>
        /// 占位Key
        /// </summary>
        public int PlaceholderKey;
        /// <summary>
        /// 根元素
        /// </summary>
        public Border RootElement { get; private set; }
        /// <summary>
        /// 原始的元素,没有设置位置与颜色
        /// </summary>
        public ApplyElement(ApplyData data)
        {
            PlaceholderKey = _maxID++;
            Data = data;
            RootElement = new()
            {
                Width = (SideLength.Width * ApplyStaticData.MinSideLength.Width) + ((SideLength.Width - 1) * ApplyStaticData.Marage),
                Height = (SideLength.Height * ApplyStaticData.MinSideLength.Height) + ((SideLength.Height - 1) * ApplyStaticData.Marage),
                BorderBrush = SY_Library.Color.BackColor(0),
                Name = "Apply_" + PlaceholderKey,
            };

            RootElement.MouseLeftButtonDown += BoxApplication.GetMainWondw().ApplyItem_MouseDown;
            RootElement.MouseMove += BoxApplication.GetMainWondw().ApplyItem_MouseMove;
            RootElement.MouseLeftButtonUp += BoxApplication.GetMainWondw().ApplyItem_MouseUp;
            RootElement.MouseLeave += BoxApplication.GetMainWondw().ApplyItem_MouseLeave;
        }

        public ApplyElement()
        { }

    }

    public static class ApplyStaticData
    {
        /// <summary>
        /// 间隔
        /// </summary>
        public static int Marage = 5;
        /// <summary>
        /// 最小边长
        /// </summary>
        public static MySize MinSideLength = new() { Width = 50, Height = 50 };
    }
}
